package com.ds.bintree.LeetCode;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/9/14 18:08
 */
public class Num958_IsCompleteTree3 {
    int size = 0;
    int maxCode = 0;
    public boolean isCompleteTree(TreeNode root) {
        if(root == null){
            return true;
        }
        recursive(root,1);
        return size == maxCode;
    }

    public void recursive(TreeNode root,int index){
        if(root == null){
            return;
        }
        size ++;
        maxCode = Math.max(maxCode,index);
        recursive(root.left,index * 2);
        recursive(root.right,index * 2 + 1);
    }
}
